package com.skytech.component.monitor.web;


import com.skytech.component.monitor.data.*;
import com.skytech.component.monitor.enterprise_data_monitoring.*;
import com.skytech.component.monitor.task.PartTask;
import com.skytech.component.monitor.task.TaskManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
public class DataController {
    @Autowired
    private MonitorDataService monitorDataService;




    @Autowired
    private ZheJiangService zheJiangService;
    @Autowired
    private PM25Service pm25Service;

    @Autowired
    private PM25DataService pm25DataService;


    @Autowired
    private ShangDongService shangDongService;


    @Autowired
    private HeiLongJiangService heiLongJiangService;
    @Autowired
    private AnHuiService anHuiService;

    @Autowired
    private TianJinNewService tianJinNewService;
    @Autowired
    private JiangSuService jiangSuService;

    @Autowired
    private BeiJingService beiJingService;

    @Autowired
    private LiaoNingNewService liaoNingNewService;

    @Autowired
    private SiChuanService siChuanService;



    @Autowired
    private ShanXiService shanXiService;

    @Autowired
    private HuBeiNewService huBeiNewService;

    @Autowired
    private HuNanService huNanService;

    @Autowired
    private FuJianService fuJianService;

    @Autowired
    private NingDongJiDiService ningDongJiDiService;

    @Autowired
    private JianSheBingTuanService jianSheBingTuanService;


    @Autowired
    private QingHaiService qingHaiService;

    @Autowired
    private GuangDongService guangDongService;


    @Autowired
    private JiLingService jiLingService;

    @Autowired
    private HeBeiService heBeiService;

    @Autowired
    private PartTask partTask;

    @Autowired
    private WaterPollutionDataService waterPollutionDataService;

    @Autowired
    private WaterPollutionService waterPollutionService;
    @GetMapping("waterPollution/monitor")
    public void waterPollution() {
        waterPollutionService.start();
    }

    @GetMapping("jiLing/monitor")
    public void jiLing() {
        jiLingService.start();
    }



    @GetMapping("jianSheBingTuan/monitor")
    public void jianSheBingTuan() {
        jianSheBingTuanService.start();
    }

    @GetMapping("guangDong/monitor")
    public void guangDong() {
        guangDongService.start();
    }

    @GetMapping("ningDongJiDi/monitor")
    public void ningDongJiDi() {
        ningDongJiDiService.start();
    }
    @GetMapping("qingHai/monitor")
    public void qingHai() {
        qingHaiService.start();
    }
    @GetMapping("huNan/monitor")
    public void huNan() {
        huNanService.start();
    }

    @GetMapping("fuJian/monitor")
    public void fuJian() {
        fuJianService.start();
    }

    @GetMapping("huBeiNew/monitor")
    public void huBeiNew() {
        huBeiNewService.start();
    }

    @GetMapping("pm25/monitor")
    public void pm25() {
        pm25Service.start();
    }
    @GetMapping("shanXi/monitor")
    public void shanXi() {
        shanXiService.start();
    }


    @GetMapping("liaoNingNew/monitor")
    public void liaoNingNew() {
        liaoNingNewService.start();
    }

    @GetMapping("beiJing/monitor")
    public void beiJing() {
        beiJingService.start();
    }



    @GetMapping("tianJinNew/monitor")
    public void tianJinNew() {
        tianJinNewService.start();
    }

    @Autowired
    private HeNanService heNanService;

    @GetMapping("zheJiangNew/monitor")
    public void zheJiangNew() {
        zheJiangService.start();
    }

    @GetMapping("heNan/monitor")
    public void heNan() {
        heNanService.start();
    }





    @GetMapping("zheJiang/monitor")
    public void zheJiang() {
        zheJiangService.start();
    }



    @GetMapping("shangDong/monitor")
    public void shangDong()  {

        shangDongService.start();
    }


    @GetMapping("heiLongJiang/monitor")
    public void heLongJiang()  {
        heiLongJiangService.start();
    }

    @GetMapping("anHui/monitor")
    public void anHui() {
        anHuiService.start();
    }


    @Autowired
    private XinJiangNewService xinJiangNewService;
    @Autowired
    private NMGMonitorService nMGMonitorService;

    @GetMapping("xinJiangNew/monitor")
    public void xinJiangNew() {
        xinJiangNewService.start();
    }

    @GetMapping("nmg/monitor")
    public void testnmg() {
        nMGMonitorService.start();
    }

    @GetMapping("siChuan/monitor")
    public void siChuan() {
        siChuanService.start();
    }


    @GetMapping("test/all")
    public String testAll() {
        List<CrawlerScript> scriptList = Arrays.asList
                (
                        anHuiService,
                        beiJingService,
                        fuJianService,
                        guangDongService,
                        heBeiService,
                        heiLongJiangService,
                        heNanService,
                        huBeiNewService,
                        huNanService,
                        jianSheBingTuanService,
                        jiLingService,
                        liaoNingNewService,
                        ningDongJiDiService,
                        nMGMonitorService,
                        qingHaiService,
                        shangDongService,
                        shanXiService,
                        siChuanService,
                        tianJinNewService,
                        xinJiangNewService,
                        zheJiangService
                );


        TaskManager taskManager = new TaskManager(scriptList);
        taskManager.setThreadNum(10);
        taskManager.rush();
        return "开始任务";
    }


    @GetMapping("test/two")
    public String testTwo() {
        List<CrawlerScript> scriptList = Arrays.asList
                (
                        siChuanService,
                        zheJiangService
                );
        TaskManager taskManager = new TaskManager(scriptList);
        taskManager.setThreadNum(2);
        taskManager.rush();
        return "开始任务";
    }

    @GetMapping("jiangSu/monitor")
    public void jiangSu() {
        jiangSuService.start();

    }


    @PostMapping("listJiangSuMonitorDataPage")
    public Page<MonitorData> listJiangSuMonitorDataPage(@RequestBody String province,@RequestBody int pageNum){

        return  monitorDataService.findByProvincePage(province,pageNum);
    }

    @GetMapping("listGasMonitorData")
    public List<PM25Data> listGasMonitorData(){
        return  pm25DataService.listGasMonitorData();
    }

    @GetMapping("listWaterPollutionData")
    public List<WaterPollutionData> listWaterPollutionData(){
        return  waterPollutionDataService.listWaterPollutionData();
    }

    @GetMapping("getScriptIndex")
    public int getScriptIndex(){
        return  partTask.next();
    }




}
